The examples below are hosted on our <b>notex.com</b> domain, but you can download and install the NOTEX script and run it on your own domains instead.

<h3>Getting stock quotes</h3>

<pre>
eval(read('/apps/notex.jsx'));
notex.usage('Get stock quotes', {symbol: 'The stock symbol to quote'});
             
// Get the stock symbol parameter
var symbol = param('symbol'); if (!symbol) notex.error('No symbol');
var url = 'http://finance.yahoo.com/q?s=' + symbol;

// Read the stock quote web page as XHTML (and cache it for 60 seconds)
var xhtml = GET('/apps/demo/services/translate/xhtml.php?token=' + notex.token + '&amp;url=' + escape(url), 60);

// Strip the namespace attribute and remove all XHTML entities (e.g. "&amp;nbsp;")
var xml = xhtml.replace(/ xmlns="[^"]+"/, '').replace(/&amp;\w+?;/g, '').toXML();

// Now return the stock quote by extracting the "Last Trade:" from the XHTML
var price = xml..tr.(th=='Last Trade:').td.big.b;

var out =
&lt;quote&gt;
  &lt;symbol&gt;{ symbol }&lt;/symbol&gt;
  &lt;price&gt;{ price.toString() }&lt;/price&gt;
  &lt;source&gt;http://finance.yahoo.com/&lt;/source&gt;
&lt;/quote&gt;

write(out.toXMLString());
</pre>

This example script <a href="http://apps.notex.com/apps/demo/services/finance/quote.js">apps.notex.com/apps/demo/services/finance/quote.js</a> does the following:
<ol>
    <li>It gets the symbol name for a US quoted stock (e.g. "AAPL" for Apple)</li>
    <li>It requests a web page from Yahoo Finance with the latest stock price</li>
    <li>It extracts the stock price from the page</li>
    <li>It returns the price in a small piece of XML</li>
</ol>
Here's a URL to run this example right now on our web server, and send the results as XML to your browser: <a href="http://apps.notex.com/notex.fcgi?token=abcd&amp;script=http://apps.notex.com/apps/demo/services/finance/quote.js&amp;symbol=AAPL">apps.notex.com/notex.fcgi?token=abcd&amp;script=http://apps.notex.com/apps/demo/services/finance/quote.js&amp;symbol=AAPL</a>
<p/>
Here's the same example, using an Apache action to handle ".jsx" files: <a href="http://apps.notex.com/apps/demo/services/finance/quote.jsx?token=abcd&amp;symbol=AAPL">apps.notex.com/apps/demo/services/finance/quote.jsx?token=abcd&amp;symbol=AAPL</a>
